import React from 'react';
import {Text, TouchableOpacity, View} from 'react-native';
import OrderStatus from "./OrderStatus";

const ActionButton = ({title, show = true, onPress = () => null}) => {
    return (
        <TouchableOpacity
            activeOpacity={1}
            style={{
                paddingHorizontal: 12,
                borderRadius: 10,
                borderWidth: 0.5,
                borderColor: '#ccc',
                marginLeft: 10,
                display: show ? 'flex' : 'none'
            }}
            onPress={onPress}
        >
            <Text style={{
                flex: 1,
                color: '#333',
                fontSize: 12,
                textAlign: 'center',
                lineHeight: 28,
                height: 28
            }}>
                {title}
            </Text>
        </TouchableOpacity>
    );
};

export default function ({order, children, style, onCancel, onExpress, onPay, onNotice, onConfirm, onRate, onDelete}) {


    const {order_id, order_status} = order;
    return (
        <View style={{
            padding: 10,
            flexDirection: 'row',
            alignContent: 'flex-end',
            ...style
        }}>
            <View style={{flex: 1}}/>
            {children}
            <ActionButton
                title={"取消订单"}
                show={order_status === OrderStatus.unpaid}
                onPress={() => {
                    onCancel && onCancel(order);
                }}
            />
            <ActionButton
                title={"支付"}
                show={order_status === OrderStatus.unpaid}
                onPress={() => {
                    onPay && onPay(order);
                }}
            />

            <ActionButton
                title={"查看物流"}
                show={order_status === OrderStatus.send}
                onPress={() => {
                    onExpress && onExpress(order);
                }}
            />

            <ActionButton
                title={"提醒卖家发货"}
                show={order_status === OrderStatus.send}
                onPress={() => {
                    onNotice && onNotice(order);
                }}
            />
            <ActionButton
                title={"确认收货"}
                show={order_status === OrderStatus.send}
                onPress={() => {
                    onConfirm && onConfirm(order);
                }}
            />
            <ActionButton
                title={"评价"}
                show={order_status === OrderStatus.success && order.buyer_rate === 0}
                onPress={() => {
                    onRate && onRate(order);
                }}
            />
            <ActionButton
                title={"删除订单"}
                show={order_status === OrderStatus.closed}
                onPress={() => {
                    onDelete && onDelete(order);
                }}
            />
        </View>
    );
}
